"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.GridWebLayout = void 0;

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _flex = _interopRequireDefault(require("../../flex"));

var _icon = _interopRequireDefault(require("../../icon"));

var _configContext = require("../../../extends/configContext");

var _excluded = ["onClick"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var Row = _flex.default.Row,
    Col = _flex.default.Col;
var gridCols = 12;

var GridWebLayout = function GridWebLayout(_ref) {
  var _ref$data = _ref.data,
      data = _ref$data === void 0 ? [] : _ref$data,
      _ref$gutter = _ref.gutter,
      gutter = _ref$gutter === void 0 ? 0 : _ref$gutter,
      _ref$bordered = _ref.bordered,
      bordered = _ref$bordered === void 0 ? true : _ref$bordered,
      _ref$columnNum = _ref.columnNum,
      columnNum = _ref$columnNum === void 0 ? 3 : _ref$columnNum,
      _ref$square = _ref.square,
      square = _ref$square === void 0 ? false : _ref$square,
      _ref$iconSize = _ref.iconSize,
      iconSize = _ref$iconSize === void 0 ? '32px' : _ref$iconSize,
      onClick = _ref.onClick,
      className = _ref.className,
      style = _ref.style;

  var _useConfig = (0, _configContext.useConfig)(),
      clsPrefix = _useConfig.clsPrefix;

  var span = gridCols / columnNum;

  var handleClick = function handleClick(event, _ref2, index) {
    var itemOnClick = _ref2.onClick,
        item = _objectWithoutProperties(_ref2, _excluded);

    event.stopPropagation();
    onClick && onClick(item, {
      event: event,
      index: index
    });
    itemOnClick && itemOnClick(item, {
      event: event,
      index: index
    });
  };

  return /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)("".concat(clsPrefix, "-grid"), className, _defineProperty({}, "".concat(clsPrefix, "-grid--bordered"), bordered && gutter === 0)),
    style: style
  }, /*#__PURE__*/_react.default.createElement(Row, {
    gutter: gutter
  }, data.map(function (item, index) {
    var _classNames2;

    var iconProps = typeof item.icon === 'string' ? {
      name: item.icon
    } : item.icon || {};
    return /*#__PURE__*/_react.default.createElement(Col, {
      key: "".concat(index, "-").concat(item.title, "-").concat(item.description),
      className: "col-".concat(span)
    }, /*#__PURE__*/_react.default.createElement("div", {
      className: (0, _classnames.default)("".concat(clsPrefix, "-grid-item"), item.className, (_classNames2 = {}, _defineProperty(_classNames2, "".concat(clsPrefix, "-grid-item--square"), square), _defineProperty(_classNames2, "".concat(clsPrefix, "-grid-item--bordered"), bordered && gutter === 0), _defineProperty(_classNames2, "".concat(clsPrefix, "-grid-item--bordered-surrounded"), bordered && gutter > 0), _defineProperty(_classNames2, 'is-clickable', typeof onClick === 'function' || typeof item.onClick === 'function'), _classNames2)),
      onClick: function onClick(e) {
        return handleClick(e, item, index);
      },
      style: item.style
    }, /*#__PURE__*/_react.default.createElement("div", {
      className: (0, _classnames.default)("".concat(clsPrefix, "-grid-item__content"), _defineProperty({}, "".concat(clsPrefix, "-grid-item__content--square"), square))
    }, /*#__PURE__*/_react.default.createElement(_icon.default, _extends({
      className: "".concat(clsPrefix, "-grid-item__icon"),
      size: iconSize
    }, iconProps)), /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(clsPrefix, "-grid-item__text")
    }, /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(clsPrefix, "-grid-item__title ").concat(clsPrefix, "-ellipsis")
    }, item.title), /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(clsPrefix, "-grid-item__description ").concat(clsPrefix, "-ellipsis")
    }, item.description)))));
  })));
};

exports.GridWebLayout = GridWebLayout;